/*
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 15/06/2004
 * Time: 20:09:03
 */
package com.talios.jira.idea;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiElement;

public class PsiUtils {
    private static final Logger LOGGER = Logger.getInstance(JiraAnnotationListener.class.toString());

    /**
     * Givin a PsiElement instance, walk up the family tree untill you find the parent we're looking for.
     *
     * @jira INTPLUG-39 Classes should also get annotated when working on an issue
     */
    public static PsiElement findParentPsiElement(PsiElement context, Class parentClass) {
        LOGGER.info("Looking for parent class " + parentClass.getName() + " for " + context.getText());
        PsiElement parent = context;
        while (parent != null && !parentClass.isInstance(parent)) {
            parent = parent.getParent();
        }

        return parent;
    }
}